package com.xb.dao;

import com.xb.entity.Meeting;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
public interface MeetingDao extends JpaRepository<Meeting,Long>, JpaSpecificationExecutor<Meeting> {

    @Query(value = "INSERT INTO meeting_join VALUES (?1,?2)", nativeQuery = true)
    @Modifying
    void insertMeetingJoin(Long uId, Long mId);

    @Query("DELETE FROM MeetingJoin mj WHERE mj.uId = ?1 AND mj.mId = ?2")
    @Modifying
    void deleteMeetingJoin(Long uId, Long mId);

    List<Meeting> findByStatusNot(long status);

    @Query("update Meeting m set m.status =?2 where m.id=?1")
    @Modifying
    void updateMeetingStatus(Long mId, long status);

}
